package com.example.myapplication.apter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.RestaurantdisheslistBean;

import java.util.List;

public class RestaurantdishesApter  extends RecyclerView.Adapter<RestaurantdishesApter.MyHolder>{
    private Context context;
    private List<RestaurantdisheslistBean.RowsBean.ProductListBean> list;


    public RestaurantdishesApter(Context context, List<RestaurantdisheslistBean.RowsBean.ProductListBean> list) {
        this.context = context;
        this.list = list;
    }


    @NonNull
    @Override
    public RestaurantdishesApter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_restaurantdishes,null);
        return new RestaurantdishesApter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RestaurantdishesApter.MyHolder holder, int position) {
        Glide.with(context).load(TokenBean.IP+list.get(position).getImgUrl()).into(holder.imgUrl);
        holder.name.setText(list.get(position).getName());
        holder.price.setText(String.valueOf(list.get(position).getPrice()));


    }



    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {

        private final ImageView imgUrl;
        private final TextView name;
        private final TextView price;


        public MyHolder(@NonNull View itemView) {
            super(itemView);
            imgUrl = itemView.findViewById(R.id.imgUrl);
            name = itemView.findViewById(R.id.name);
            price = itemView.findViewById(R.id.price);

        }
    }


}








